<?php

use yii\helpers\Html;
use yii\grid\GridView;
use common\models\Commentstatus;
use yii\grid\Column;

/* @var $this yii\web\View */
/* @var $searchModel common\models\CommentSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = '合作管理';
$this->params['breadcrumbs'][] = $this->title;
?>
<script type="text/javascript" src="js/jquery-2.1.1.min.js"></script>
<div class="comment-index">

    <h1><?= Html::encode($this->title) ?></h1>
    <?php // echo $this->render('_search', ['model' => $searchModel]); ?>


    <?= GridView::widget([
        'dataProvider' => $dataProvider,
        'filterModel' => $searchModel,
        'columns' => [
            // ['class' => 'yii\grid\SerialColumn'],

            //'id',
            [
                'attribute' => 'id',
                'contentOptions' => ['width' => '30px'],
            ],


            [
                'attribute' => 'name',
                'label' => '昵称',
                'value' => 'name',
            ],
            [
                'attribute' => 'link',
                'label' => '联系方式',
                'value' => 'link',
            ],
            [
                'attribute' => 'create_tm',
                'label' => '时间',
                'format' => ['date', 'php:Y-m-d'],

            ],
            [
                'attribute' => 'content',
                'label' => '内容',
                'value' => 'content',
            ],
            [
                'label' => '状态',
                //设置筛选选项
                'filter' => [0 => '待处理', 1 => '已处理'],
                'attribute' => 'status',
                'format' => 'raw',
                'value' => function ($data) {
                    return ($data->status == 0) ? '待处理' : '已处理';
                }
            ],
            [
                'header' => '操作',
                'class' => 'yii\grid\ActionColumn',
                //设置显示模板
                'template' => '{send} ',
                //下面的按钮设置，与上面的模板设置相关联
                'buttons' => [
                    'send' => function ($url, $model, $key) {
                        $options = [
                            'title' => Yii::t('yii', '审核'),
                            'aria-label' => Yii::t('yii', '审核'),
//                            'data-method'=>'post',
                            'data-pjax' => '0',
                            'onclick' => "test(this)",
                            'data-toggle' => "modal",
                            'data-target' => "#myModal",
                            'class' => "glyphicon glyphicon-log-out",
                            'id' => $key,
                            'style'=>'margin:5px',
                        ];
                        return Html::button('', $options);
                        // return Html::a('<span class="glyphicon glyphicon-check"></span>',$url,$options);

                    },
//                    'del' => function ($url, $model, $key) {
//                        return '<a href="' . \yii\helpers\Url::toRoute(['test/del', 'id' => $key]) . '" class="btn btn-danger">删除</a>';
//                    },
                ],
            ],



        ],
    ]); ?>
</div>
<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel">回复消息</h4>
            </div>
            <input type="hidden" class="content123" name="id">
            <input type="text" class="form-control" id="bodycon" placeholder="请输入内容">
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
                <button type="button" class="btn btn-primary" onclick="a()">提交</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
<script>
    var id;
    function test(element) {
        id = element.id
    }
    function a() {
        var text = document.getElementById("bodycon").value;
        if (text.length == 0) {
            alert("内容不允许为空")
            return false;
        }
        $.ajax({

            url: "index.php?r=user/coosend",
            data: {id:id ,text:text},
            type: "get",
            dataType : 'json',
            success: function (msg) {
                if (msg.status ==200){
                    alert(msg.msg)
                    $('#myModal').modal('hide')
                    window.location.reload()
                }else {
                    alert(msg.msg)
                }

            }


        });

    }
</script>



